package com.xuxin.baby.presenter;

import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.bean.UploadFilesBean;
import com.xuxin.baby.contract.UploadFilesContract;
import com.xuxin.baby.model.UploadFilesModel;

import java.util.List;

import okhttp3.MultipartBody;

/**
 * Created by xu_xin
 * Created on 2020/10/29 0029
 * 上传图片
 */
public class UploadFilesPresenter implements UploadFilesContract.Presenter {
    private final UploadFilesModel model;
    private final UploadFilesContract.View view;

    public UploadFilesPresenter(UploadFilesContract.View view) {
        this.view = view;
        model = new UploadFilesModel();
    }

    @Override
    public void uploadFiles(String tenantId, String token, String objectId, String objectName, String objectField, List<MultipartBody.Part> parts) {
        if (null != model) {
            model.uploadFiles(this, tenantId, token, objectId, objectName, objectField, parts);
        }
    }

    @Override
    public void onSuccess(UploadFilesBean uploadFilesBean) {
        if (null != view) {
            view.onSuccess(uploadFilesBean);
        }
    }

    /**
     * 以下内容复用(用于请求完成后的操作)
     */
    @Override
    public void onError(BaseBean baseBean) {
        if (null != view) {
            view.onError(baseBean);
        }
    }

    @Override
    public void onComplete() {
        if (null != view) {
            view.onComplete();
        }
    }
}